/*
 * @Description: 全宗reducer
 * @Author: Rfan
 * @Date: 2022-01-08 16:30:05
 * @LastEditTime: 2022-06-22 17:41:07
 */

import {
  ADD_LEVEL_BY_ID,
  SET_AUTO_FILING_MSG,
  SET_SELECT_AT,
  SET_SELECT_AT_ID,
  SET_SELECT_FILE,
  SET_SELECT_FOND_ID,
  SET_SELECT_NODE_ID,
  SET_AUTO_FILING_LOADING
} from '../constants';

export const ArrangementReducer = (state, action) => {
  switch (action.type) {
    /**
     * @description:
     */
    case SET_SELECT_FILE:
      return {
        ...state,
        selectFile: action.data
      };

    /**
     * @description: 设置选中的全宗
     */
    case SET_SELECT_FOND_ID:
      return {
        ...state,
        selectFondId: action.id
      };

    /**
     * @description: 设置选中的档案类型
     */
    case SET_SELECT_AT:
      return {
        ...state,
        selectAT: action.data
      };

    /**
     * @description: 设置选中的档案类型
     */
    case SET_SELECT_AT_ID: {
      return {
        ...state,
        selectATId: action.id
      };
    }

    /**
     * @description: 设置选中的档案类型
     */
    case SET_SELECT_NODE_ID: {
      return {
        ...state,
        selectNodeId: action.id
      };
    }

    /**
     * @description: 加载level表格数据及相关数据
     * @param {Array} data level列表
     * @param {Number} id 档案类型ID
     * @return {*}
     */
    case ADD_LEVEL_BY_ID: {
      return {
        ...state,
        levelList: action.data,
        tabList: [action.data[0]],
        currentAt: action.id
      };
    }

    /**
     * @description: 展示自动组卷请求loading
     */
    case SET_AUTO_FILING_LOADING: {
      return {
        ...state,
        autoFiling: {
          loading: action.status || false,
          info: {}
        }
      };
    }

    /**
     * @description: 设置自动组卷结果
     */
    case SET_AUTO_FILING_MSG: {
      return {
        ...state,
        autoFiling: {
          loading: false,
          info: action.data
        }
      };
    }

    default:
      console.log('untouched', action);
      return state;
  }
};
